package com.yp.infrastructure.axon.example

import org.axonframework.commandhandling.CommandHandler
import org.axonframework.eventhandling.EventHandler
import org.axonframework.modelling.command.AggregateIdentifier
import org.axonframework.modelling.command.AggregateLifecycle
import org.axonframework.spring.stereotype.Aggregate


@Aggregate
class PartnerAggregate constructor() {

    @AggregateIdentifier
    lateinit var id: String

    lateinit var name: String

    @CommandHandler
    constructor(cmd: CreatePartnerCommand) : this() {
        AggregateLifecycle.apply(CreatePartnerEvent(cmd.id, cmd.name));
    }

    @EventHandler
    fun on(e : CreatePartnerEvent) {
        this.id = e.id
        this.name = e.name
    }

}